<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>敞口提醒配置</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">项目类型</div>
                    <div class="field">
                        <input name="prjTypCd" id="prjTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">主体</div>
                    <div class="field">
                        <input name="curOrgCd" id="curOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round" onclick="searchInfo();">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round" onclick="clearInfo();">清空</span>
                    <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>
<div id="div_add_type" style="display:none">
    <form id="div_add_type_form">
        <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
            <div class="fieldBox col_50">
                <div class="label">事业部</div>
                <div class="field">
                    <select name="win_add_buOrgCd" id="win_add_buOrgCd" data-value="" validate="{required:true, select:true}">
                        <option value="" >请选择</option>
                        <c:forEach items="${_buOrgCdList}" var="kv"  begin="0"
                                   step="1">
                            <option value="${kv.key}">${kv.value}</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">主体</div>
                <div class="field">
                    <select name="win_add_curOrgCd" id="win_add_curOrgCd" data-value="" validate="{required:true, select:true}">
                        <option value="" >请选择</option>
                        <c:forEach items="${_curOrgCdList}" var="curOrgCd"  begin="0"
                                   step="1">
                            <option value="${curOrgCd.key}">${curOrgCd.value}</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">业务模式</div>
                <div class="field">
                    <select name="win_add_busTypCd" id="win_add_busTypCd"   data-value="" validate="{required:true, select:true}">
                        <option value="" >请选择</option>
                        <c:forEach items="${_busTypCdList}" var="busTypCd" begin="0" step="1">
                            <option value="${busTypCd.key}">${busTypCd.value}</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">项目类型</div>
                <div class="field">
                    <select name="win_add_prjTypCd" id="win_add_prjTypCd" data-value=""  validate="{required:true, select:true}">
                        <option value="" >请选择</option>
                        <c:forEach items="${_prjTypCdList}" var="prjTypCd"  begin="0" step="1">
                            <option value="${prjTypCd.key}">${prjTypCd.value}</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div id="win_np_block_id" style="display:block">
                <div class="fieldBox col_50">
                    <div class="label" id="div_remindAmtOne_column_tip">提醒额度一阶段</div>
                    <div class="field">
                        <input name="win_add_remindAmtOne" id="win_add_remindAmtOne" type="text" class="ui-textbox" value="" validate="{maxlength:13}">
                    </div>
                </div>
            </div>
            <div id="win_np_block_id" style="display:block">
                <div class="fieldBox col_50">
                    <div class="label" id="div_remindAmtTwo_column_tip">提醒额度二阶段</div>
                    <div class="field">
                        <input name="win_add_remindAmtTwo" id="win_add_remindAmtTwo" type="text" class="ui-textbox" value="" validate="{maxlength:13}">
                    </div>
                </div>
            </div>
            <div id="win_np_block_id" style="display:block">
                <div class="fieldBox col_50">
                    <div class="label" id="div_remindAmtThree_column_tip">提醒额度三阶段</div>
                    <div class="field">
                        <input name="win_add_remindAmtThree" id="win_add_remindAmtThree" type="text" class="ui-textbox" value="" validate="{maxlength:13}">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/remindconfig/splremindconfig/initList.do',
            method: 'get',
            columns: [
                {display: '序号', name: 'id', minWidth: 100, align: 'left', enabledSort: false},
                {display: '事业部', name: 'buOrgCd', minWidth: 100, align: 'center',
                    render:function(rowdata,index,value){
                    var list = ${buOrgCdList};
                        for(var i=0;i<list.length;i++){
                            if(rowdata.buOrgCd==list[i].key){
                                return list[i].value;
                            }
                        }
                    }
                },
                {display: '业务模式', name: 'busTypCd', minWidth: 100, align: 'center',
                    render:function(rowdata,index,value){
                        var list = ${busTypCdList};
                        for(var i=0;i<list.length;i++){
                            if(rowdata.busTypCd==list[i].key){
                                return list[i].value;
                            }
                        }
                    }},
                {display: '项目类型', name: 'prjTypCd', minWidth: 100, align: 'center',
                    render:function(rowdata,index,value){
                        var list = ${prjTypCdList};
                        for(var i=0;i<list.length;i++){
                            if(rowdata.prjTypCd==list[i].key){
                                return list[i].value;
                            }
                        }
                    }},
                {display: '主体', name: 'curOrgCd', minWidth: 100, align: 'center',
                    render:function(rowdata,index,value){
                        var list = ${curOrgCdList};
                        for(var i=0;i<list.length;i++){
                            if(rowdata.curOrgCd==list[i].key){
                                return list[i].value;
                            }
                        }
                    }},
                {display: '提醒额度(元)-一阶段', name: 'remindAmtOne', minWidth: 120, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.remindAmtOne){
                            return '&yen;'+rowdata.remindAmtOne;
                        }
                    }
                },
                {display: '提醒额度(元)-二阶段', name: 'remindAmtTwo', minWidth: 120, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.remindAmtTwo){
                            return '&yen;'+rowdata.remindAmtTwo;
                        }
                    }
                },
                {display: '提醒额度(元)-三阶段', name: 'remindAmtThree', minWidth: 120, align: 'right',
                    render:function(rowdata,index,value){
                        if(rowdata.remindAmtThree){
                            return '&yen;'+rowdata.remindAmtThree;
                        }
                    }
                },
                {display: '配置人', name: 'crtUsrNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '配置日期', name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
                {display: '状态', name: 'status', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowData){
                        if(rowData.status==0){
                            return "启用";
                        }else{
                            return "作废";
                        }
                    }	},
                { display: '操作', minWidth: 80 , align:'left',
                    render: function (rowdata, rowindex, value){
                        var d = "";
                        if(rowdata.status == 0){
                            if(rowdata.id){
                                d='<a class="sq-button-hasicon" href="javascript:deleteDB(';
                                d+="'"+rowdata.id+"'";
                                d+=')"><i class="sqBtnIco_7"></i>作废</a>';
                            }
                        }
                        return d;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("buOrgCd").setData(${buOrgCdList});
        //项目类型
        $("#prjTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("prjTypCd").setData(${prjTypCdList});
        //主体
        $("#curOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("curOrgCd").setData(${curOrgCdList});
        <%--//业务模式--%>
        <%--$("#busTypCd").ligerComboBox({--%>
        <%--    valueField: 'key',--%>
        <%--    textField: 'value'--%>
        <%--});--%>
        <%--liger.get("busTypCd").setData(${busTypCdList});--%>
        $("#searchBar").ligerForm();


        $("#pageloading").hide();


        // $("#clearBtn").click(function (event) {
        //
        // });

        callback = function () {
            grid.reload();
        };

    });
    /* 查询 */
    function searchInfo(){
        var form = liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        grid.reload();
    }
    // $("#searchBtn").click(function (event) {
    //     var form = liger.get("searchBar");
    //     var data = form.getData();
    //     for (name in data) {
    //         grid.setParm(name, data[name]);
    //     }
    //     grid.reload();
    // });

    /* 清空 */
    function clearInfo(){
        clearLigerForm("searchBar");
    }
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    var ligerPersonForm;
    function add() {
        $.ligerDialog.SQopen({
            width: 800,
            top: 100,
            buttons: [
                {
                    text: "确定", cls: 'l-dialog-btn-ok', onclick: function () {
                        saveInfo();
                    }
                }, {
                    text: "取消", cls: 'l-dialog-btn-no', onclick: function () {
                        $.ligerDialog.hide();
                    }
                }
            ],
            title: '新增',
            target: $("#div_add_type")
        });
        ligerPersonForm = $("#div_add_type_form").ligerForm({
            validate: true
        });
        clearLigerForm("div_add_type_form");
    }
   /* //定义父级调用事件
    frameElement.dialog.onOk = function () {
        save();
    }
    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }*/

    function saveInfo(){
        if (!ligerPersonForm.valid()) {
            UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
            return false; //验证不通过，不执行以下代码
        }
        var _data = ligerPersonForm.getData();
        var _url = '<%=path%>/remindconfig/splremindconfig/add.do';
        var wait_dialog=$.ligerDialog.SQalert({
            content: LogUtils.LOG_CMM_LOADING,
            SQ_type: "waitting",
            onClose: function () {
            }
        });
        $.ajax({
            type: 'post',
            url: _url,
            timeout: 5000,
            data: _data,
            dataType: "json",
            success: function (msg) {
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    //frameElement.dialog.close();
                    //清空字段值
                    // resetAddCstNpForm(ligerPersonForm);
                    $.ligerDialog.hide();
                    //回调刷新列表
                    clearInfo();
                    searchInfo();
                }else {
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                }
            }
        });
    }
    //重置新增选择表单
    function resetAddCstNpForm(ligerPersonForm){
        $("#win_add_remindAmtOne").val("");
        $("#win_add_remindAmtTwo").val("");
        $("#win_add_remindAmtThree").val("");
        $("#win_add_buOrgCd").val(" ");
        $("#win_add_curOrgCd").val(" ");
        $("#win_add_busTypCd").val(" ");
        $("#win_add_prjTypCd").val(" ");
    }

    function deleteDB(rowdata_id){
        //作废
        var _id = rowdata_id;
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
            if(flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:{id:_id},
                url: '<%=path%>/remindconfig/splremindconfig/invalid.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        //回调刷新列表
                        clearInfo();
                        searchInfo();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
</script>

</body>
</html>
